package com.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.entity.StuInfo;
import com.edu.mapper.StuInfoMapper;
import com.edu.service.StuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.security.auth.login.Configuration;
import java.util.List;

/**
 * @program: graduate
 * @description:
 * @author: K.faWu
 * @create: 2021-05-24 22:42
 **/
@Service
public class StuInfoServiceImpl extends ServiceImpl<StuInfoMapper, StuInfo> implements StuInfoService {

    @Autowired
    private StuInfoMapper stuInfoMapper;

    @Override
    public boolean isok(Long stuId) {
        QueryWrapper<StuInfo> stuInfoQueryWrapper = new QueryWrapper<>();
        stuInfoQueryWrapper.eq("stu_id", stuId);
        List<StuInfo> stuInfoList = stuInfoMapper.selectList(stuInfoQueryWrapper);
        if(stuInfoList == null || stuInfoList.size() != 1){
            return false;
        }
        StuInfo stuInfo = stuInfoList.get(0);
        if(stuInfo.getProId() == null || stuInfo.getProId() == 0 ||
                stuInfo.getCityId() == null || stuInfo.getCityId() == 0 ||
                stuInfo.getAreaId() == null || stuInfo.getAreaId() == 0 ||
                stuInfo.getAreaInfo() == null || stuInfo.getAreaInfo() == "" ||
                stuInfo.getSourceInfo() == null || stuInfo.getSourceInfo() == "" ||
                stuInfo.getGraduationDate() == null){
            return false;
        }
        return true;
    }

    @Override
    public void upStuInfo(StuInfo stuInfo) {
        QueryWrapper<StuInfo> stuInfoQueryWrapper = new QueryWrapper<>();
        stuInfoQueryWrapper.eq("stu_id", stuInfo.getStuId());
        List<StuInfo> stuInfos = stuInfoMapper.selectList(stuInfoQueryWrapper);
        if(CollectionUtils.isEmpty(stuInfos)){
            stuInfoMapper.insert(stuInfo);
        }else{
            stuInfoMapper.update(stuInfo, stuInfoQueryWrapper);
        }

    }
}
